//
//  TwoViewController.m
//  5-24
//
//  Created by 王成龙 on 16/5/24.
//  Copyright © 2016年 wcl. All rights reserved.
//

#import "TwoViewController.h"
#import "Person.h"

@interface TwoViewController ()

@end

@implementation TwoViewController
{
    NSMutableArray * aabb;
}


- (void)viewDidLoad {
    
    [super viewDidLoad];
    self.navigationItem.title=@"么么的ip6sp";
    self.view.backgroundColor=[UIColor blueColor];//背景颜色

    NSBundle*bundle=[NSBundle mainBundle];
    NSURL*url=[bundle URLForResource:@"PIM00001" withExtension:@"vcf"];
    NSString *text = [[NSString alloc] initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    // NSLog(@"读取数据：%@", text);
    
    NSArray *arr = [text componentsSeparatedByString:@"\n"];
    Person*item;
    NSMutableArray *tmp = [NSMutableArray new];
    for(NSString*p in arr){
        if([p hasPrefix:@"BEGIN"])
        {
            item=[Person new];
        }else if([p hasPrefix:@"END"])
        {
            [tmp addObject:item];
        }else if([p hasPrefix:@"TEL"])
        {
            
            NSArray *components=[p componentsSeparatedByString:@":"];
            NSString *app=components[1];
            item.haoma=app;
        }
        else if ([p hasPrefix:@"FN;"]){
            NSArray *upperComponents = [p componentsSeparatedByString:@":"];
            NSString *name = upperComponents[1];
            name = [name stringByReplacingOccurrencesOfString:@"=" withString:@"%"];
            name = [name stringByRemovingPercentEncoding];
            
            // NSlog(@"FN:%@",name);
            item.name = name;
        }
        
        
        aabb=tmp;
    }

    // Do any additional setup after loading the view.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   // return 20;
    return aabb.count;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    UITableViewCell * call = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
//    call.textLabel.text =@"oh my day";
//
  //UITableViewCellAccessoryDisclosureIndicator;//后面箭头
    
    
    UITableViewCell * cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
        Person * p = aabb[indexPath.row];
        cell.textLabel.text = p.name;
        cell.detailTextLabel.text = p.haoma;
    
     cell.backgroundColor =[UIColor colorWithRed:20*indexPath.row/255.0 green:40*indexPath.row/9000.0 blue:60*indexPath.row/255.0 alpha:1];
        return cell;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
